/**
 * Created by wangshaohua on 2018/2/4.
 */
moduleLearningMap.controller("LearningMapTaskMessageQuery", function (LanguageService, LearningMapTaskMessageExerciseResource, $scope, $log, $state, $stateParams, GeneralResource, LoadingService, ConstantService, DialogService) {

    initPage($scope);
    $scope.$on("$viewContentLoaded", function () {
        pageOnLoad($scope);
        ConstantService.addState($state.current, true, LanguageService.language('学习地图任务课程反馈管理'));
        $scope.query(1);
    });


    $scope.query = function (pageNo) {
        //LoadingService.show();
        LearningMapTaskMessageExerciseResource.find({pageNo: pageNo - 1, pageSize: 10, status: 'APPROVED'}, {}, function (queryResult) {
            $log.debug("查询结果", queryResult.data);
            $scope.taskMessageResults = queryResult.data;
            $scope.pagination.setPage(queryResult.data, pageNo);
            //LoadingService.hide();
        });
    };
    $scope.pagination = new Pagination();
    $scope.pagination.setPageClickFn($scope.query);

    $scope.download = function (taskMessage) {
        if (!StringUtils.isNlOrUndOrEmpty(taskMessage)) {
            window.open($$CambioConfig.DOWNLOAD_URL.format({id: taskMessage.file}), '_blank');
        }
    }

    $scope.reject = function (taskMessage) {
        const learningMapUserStudyTaskId = taskMessage.learningMapUserStudyTaskId;
        Alert.confirm(function () {
            const params = {
                userTaskStudyId: learningMapUserStudyTaskId,
                userTaskStudyContentId: taskMessage.id
            }
            LearningMapTaskMessageExerciseResource.reject(params, {}, function (result) {
                $scope.query(1);
            });
        })
    }

    $scope.approve = function (taskMessage) {
        const learningMapUserStudyTaskId = taskMessage.learningMapUserStudyTaskId;
        Alert.confirm(function () {
            const params = {
                userTaskStudyId: learningMapUserStudyTaskId,
                userTaskStudyContentId: taskMessage.id
            }
            LearningMapTaskMessageExerciseResource.approve(params, {}, function (result) {
                $scope.query(1);
            });
        })
    }
});